#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int T; cin >> T;
    while (T--){
        int a, b, k; cin >> a >> b >> k;
        if(a>b) swap(a, b);
        if(abs(a-b)<=k) {cout << 1 << "\n"; continue;}
        if((b-a)%(k+1)) {cout << 0 << "\n"; continue;}
        int c = 1, d = k+2;
        map<int, int> m;
        m[c] = d;
        while (d<=b && c<=a){
            int t = d;
            d += (d-c)*(k+2);
            c = t;
            ++c, ++d;
            m[c] = d;
        }
        auto p = m.lower_bound(a);
        int aa = p->first, bb = p->second;
        if(a == aa && b == bb) {cout << 0 << "\n"; continue;}
        --p; aa = p->first, bb = p->second;
        if(bb + (a-aa)*(k+2) == b) {
            if(a == bb) {cout << 1 << "\n"; continue;}
            else {cout << 0 << "\n"; continue;}
        }
        else {cout << 1 << "\n"; continue;}

    }
    return 0;
}